﻿using Gonte.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace MyUtilitiesTest
{
    /// <summary>
    ///This is a test class for ObjectTypeConverterTest and is intended
    ///to contain all ObjectTypeConverterTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ObjectTypeConverterTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///Converts from string to guid test
        ///</summary>
        [TestMethod()]
        public void ConvertFromStringToGuidTest()
        {
            Guid expected = new Guid("5daa64c2-2c28-47d7-86d4-0dc378a0568b");
            Guid actual = ObjectTypeConverter.ConvertValue<Guid>("5daa64c2-2c28-47d7-86d4-0dc378a0568b");

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///Converts from string to datetime test
        ///</summary>
        [TestMethod()]
        public void ConvertFromStringToDatetimeTest()
        {
            DateTime expected = new DateTime(2005,5,25,2,30,18);
            DateTime actual = ObjectTypeConverter.ConvertValue<DateTime>("5/25/2005 2:30:18 AM");

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///Converts from string to an enumeration test
        ///</summary>
        [TestMethod()]
        public void ConvertFromStringToEnumerationTest()
        {
            EnumerationTest expected = EnumerationTest.EnumItem2;

            EnumerationTest actual = ObjectTypeConverter.ConvertValue<EnumerationTest>("20");
            Assert.AreEqual(expected, actual);

            actual = ObjectTypeConverter.ConvertValue<EnumerationTest>("EnumItem2");
            Assert.AreEqual(expected, actual);
        }
    }
}
